<?php

namespace core\lib\schema;

use support\Db;

class Schema
{
    /**
     * 判断表是否存在
     *
     * @param string $tablename
     * @return boolean
     */
    public static function tableExists(string $tablename): bool
    {
        $tables = Db::schema()->getTables();
        $tables = array_column($tables, 'name');
        return in_array($tablename, $tables);
    }

    /**
     * 所有的表
     *
     * @return array
     */
    public static function tables(): array
    {
        return  Db::schema()->getTables();
    }

    public static function dropTable(string $tablename)
    {
        return Db::schema()->dropIfExists($tablename);
    }
}
